package com.example.user.myhjjf_app.presenter;

import android.graphics.Color;
import android.util.Log;

import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.map.PolygonOptions;
import com.baidu.mapapi.map.Stroke;
import com.baidu.mapapi.map.TextOptions;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.model.LatLngBounds;
import com.baidu.mapapi.search.core.SearchResult;
import com.baidu.mapapi.search.district.DistrictResult;
import com.baidu.mapapi.search.district.DistrictSearch;
import com.baidu.mapapi.search.district.DistrictSearchOption;
import com.example.user.myhjjf_app.view.Activity_District;
import com.example.user.myhjjf_app.view.Activity_Login;

import java.util.List;

/**
 * Created by User on 2017/8/15.
 */

public class Presenter_Painting implements MvpPainting{
    DistrictSearch mdistrictSearch;
    OverlayOptions ooplygn;
    OverlayOptions ooplygn2;
    String cityName;
    int Colors;
    @Override
    public void getPainting(String cityName,  int Colors) {
                    this.cityName = cityName;
                    this.Colors = Colors;
                    mdistrictSearch = DistrictSearch.newInstance();
                    mdistrictSearch.setOnDistrictSearchListener(this);
                    mdistrictSearch.searchDistrict(new DistrictSearchOption().cityName(cityName).districtName(cityName));
    }



    @Override
    public void onGetDistrictResult(DistrictResult districtResult) {
        if (districtResult == null) {
            return;
        }
        if (districtResult.error == SearchResult.ERRORNO.NO_ERROR) {
            List<List<LatLng>> poinsList = districtResult.getPolylines();
            if (poinsList == null) {
                return;
            }
            ListDistrictResult.getListDistrictResult().setList(districtResult);
            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            for (List<LatLng> polyline : poinsList) {
                ooplygn = new PolygonOptions().points(polyline).stroke(new Stroke(5, Color.BLACK)).fillColor(Colors);
                Activity_Login.baiduMap.addOverlay(ooplygn);
                for (LatLng latLng : polyline) {
                    builder.include(latLng);
                }
            }
            ooplygn2 = new TextOptions().text(cityName).fontSize(40).fontColor(0xFF000000).position(districtResult.getCenterPt());
            Activity_Login.baiduMap.addOverlay(ooplygn2);
            Activity_Login.baiduMap.setMapStatus(MapStatusUpdateFactory.newLatLngBounds(builder.build()));
            MapStatusUpdate u = MapStatusUpdateFactory.zoomTo(9);
            Activity_Login.baiduMap.animateMapStatus(u);
        }
    }

}
